feat(db): support SearchDirection in QueryTransactionsParams#1536
Conversation
|
Hi @EvanYan1024 , thanks for submitting this and for the effort. I'll review ASAP. |
|
Hi @EvanYan1024 , thanks for creating the issue. Please, have a look at the unit-tests. There must be something there that if fixed might solve also the integration tests. |
4888046 to
27f5385
Compare
@adecaro Hi,I have fixed all CI errors. thanks |
27f5385 to
6e1d50a
Compare
| // SearchDirection is the direction of the search. | ||
| // If nil, defaults to FromBeginning (ascending by stored_at) for backward compatibility. | ||
| // Set explicitly to override: &FromLast for descending, &FromBeginning for ascending. | ||
| SearchDirection *SearchDirection |
There was a problem hiding this comment.
I think we don't need the pointer here because 0 (the default value) represents searching from last. No?
There was a problem hiding this comment.
You're right — removed the pointer. Now it uses plain SearchDirection with the zero value (FromLast) defaulting to DESC, consistent with QueryMovementsParams. Updated and force-pushed. Thanks!
|
Hi @EvanYan1024 , I think we can remove the pointer and then we are good. |
6e1d50a to
4ba718b
Compare
|
@EvanYan1024 , please, run |
71f980b to
07590d2
Compare
07590d2 to
664bc61
Compare
adecaro
left a comment
There was a problem hiding this comment.
LGTM. Thanks much @EvanYan1024
0246911 to
1e993ba
Compare
QueryTransactions previously hard-coded ORDER BY stored_at ASC, making it impossible for callers to request newest-first ordering. Add a SearchDirection field to QueryTransactionsParams, consistent with the existing field in QueryMovementsParams. The zero value (FromLast) produces DESC ordering, matching the convention. Signed-off-by: Evan <evanyan@sign.global>
1e993ba to
b11c9f4
Compare
fixed🙏 |
Closes #1539
Summary
QueryTransactionspreviously hard-codedORDER BY stored_at ASC, making itimpossible for callers to request newest-first ordering.
This PR adds a
*SearchDirectionfield (pointer) toQueryTransactionsParams:nil(default): ascending order — preserves backward compatibility with all existing callers&FromLast: descending order (newest first)&FromBeginning: ascending order (oldest first, explicit)Using a pointer avoids the zero-value ambiguity (
FromLast = 0), ensuringexisting code that uses
QueryTransactionsParams{}continues to work unchanged.Changes
driver/common.go: Add*SearchDirectionfield toQueryTransactionsParamssql/common/transactions.go: AddtransactionOrderBy()helper that defaults to ASC when direction is nildbtest/transactions.go: AddSearchDirection ASC/DESCtest cases using records with distinct timestampsTest plan
go testpasses for memory, SQLite, and PostgreSQL backends locallyTestQueryTransactions) confirms default query usesORDER BY stored_at ASC